/*
 * @Author: shiguo
 * @Date: 2022-04-18 18:40:07
 * @LastEditors: shiguo
 * @LastEditTime: 2023-03-23 15:07:57
 * @FilePath: /@aks-dev/easyui/utils/mode.ts
 */
import type { CallBack } from './index.d'




import { PanResponder, Keyboard, Linking } from 'react-native'
export const keyboardDismissHandlers = PanResponder.create({
    onStartShouldSetPanResponder: () => true,
    onPanResponderGrant: Keyboard.dismiss
}).panHandlers




export const panHandlersCallback = (props: { GrantCallback: CallBack, MoveCallback: CallBack, ReleaseCallback: CallBack }) => {
    return PanResponder.create({
        onStartShouldSetPanResponder: () => true,
        onMoveShouldSetPanResponder: () => true,
        onPanResponderGrant: props.GrantCallback,
        onPanResponderMove: props.MoveCallback,
        onPanResponderRelease: props.ReleaseCallback
    }).panHandlers

}


export const callTelephone = (phone: number | string) => {

    let tel = 'tel:' + phone
    Linking.canOpenURL(tel).then((supported) => {
        if (supported) {
            Linking.openURL(tel)
        } else {
            console.warn('[sg:callTelephone 不支持]', { supported, tel })
        }
    }).catch(error => {
        console.warn('[sg:callTelephone catch]', { error, tel })
    })

}

